package com.example.xmh.utils;

import org.springframework.util.StringUtils;

import java.util.regex.Pattern;

/**
 * 校验手机号是否合规的工具类
 */
public class CheckUtils {
    private static final String REGEX_MOBILE = "((\\+86|0086)?\\s*)((134[0-8]\\d{7})|(((13([0-3]|[5-9]))|(14[5-9])|15([0-3]|[5-9])|(16(2|[5-7]))|17([0-3]|[5-8])|18[0-9]|19(1|[8-9]))\\d{8})|(14(0|1|4)0\\d{7})|(1740([0-5]|[6-9]|[10-12])\\d{7}))";
    private static final String LEGAL_CHAR = "[a-zA-z0-9]*";

    /**
     * 强！！！校验手机号
     *
     * @param phone 手机号
     * @return boolean true:是  false:否
     */
    public static boolean isMobileStrong(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return false;
        }
        return Pattern.matches(REGEX_MOBILE, phone);
    }

    /**
     * 弱！！！校验手机号
     *
     * @param phone 手机号
     * @return boolean true:是   false:否
     */
    public static boolean isMobileWeak(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return false;
        }
        return phone.length() == 11;
    }

    /**
     *
     */
    public static boolean isLegal(String str){
        return Pattern.matches(LEGAL_CHAR,str);
    }
}
